package br.com.positrot.model.vo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import br.com.positrot.model.vo.exception.ConfiguracaoInvalidaException;
import br.com.positrot.model.vo.exception.ValidacaoDadosException;

@SuppressWarnings("serial")
@Entity
@Table(name="acesso.permissao")
public class PermissaoVO implements Serializable, Persistivel {

		
	public enum TipoPermissao{
		
		CADASTRO(1),
		LEITURA(2),
		ALTERACAO(3);
		
		private int id;
		
		TipoPermissao(int id){
			this.id = id;
		}
		
		public int getId(){
			return this.id;
		}
		
		
		
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="idpermissao", nullable=false)
	private int idPermissao;
	
	@Column(name="tipo", nullable=false)
	private String tipo; 
			
	
	public int getIdPermissao() {
		return idPermissao;
	}

	public void setIdPermissao(int idPermissao) {
		this.idPermissao = idPermissao;
	}

	public String getTipo() {
		return tipo;
	}

	public void setTipo(String tipo) {
		this.tipo = tipo;
	}
	
	public TipoPermissao getTipoPermissao(){
		
		switch(idPermissao){
		case 1:
			
			return TipoPermissao.CADASTRO;
			
		case 2:
			
			return TipoPermissao.LEITURA;
			
		case 3:
			
			return TipoPermissao.ALTERACAO;
			
		default :
		
			return null;
		
		}
		
	}

	@Override
	public void configurarDados() throws ConfiguracaoInvalidaException {
		
	}

	@Override
	public void validarDados() throws ValidacaoDadosException {
		
	}
	
	@Override
	public String toString(){
		
		return this.getTipoPermissao().toString();
		
	}

	@Override
	public boolean equals(Object obj) {
		
		if (obj instanceof PermissaoVO){
			
			if ( ((PermissaoVO)obj).getIdPermissao() == this.getIdPermissao()){
				return true;
			}else{
				return false;
			}
			
		}else{
			return false;
		}
		
		
	}

	@Override
	public int hashCode() {
		
		return super.hashCode();
	}
	
	
	

}
